

       package com.example.myapplication9;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import java.util.StringTokenizer;

import static android.support.v4.content.ContextCompat.startActivity;

        public class MainActivity extends AppCompatActivity {

            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
                Button botton = findViewById(R.id.button);//顺序查找
                Button botton2 = findViewById(R.id.button2);//二分查找
                Button botton3 = findViewById(R.id.button3);//插值查找
                Button botton4 = findViewById(R.id.button4);//斐波那契查找
                Button botton5 = findViewById(R.id.button5);//二叉树查找
                Button botton6 = findViewById(R.id.button6);//分块查找
                Button botton7= findViewById(R.id.button7);//哈希表查找
                final EditText editText = findViewById(R.id.editText);
                final EditText editText1 = findViewById(R.id.editText2);
                final EditText editText2 = findViewById(R.id.editText3);

                botton.setOnClickListener(new View.OnClickListener() {


                    @Override
                    public void onClick(View v) {
                        StringTokenizer Tokenizer = new StringTokenizer(editText1.getText().toString());
                        Integer[] ant = new Integer [6];
                        int a = 0;
                        while (Tokenizer.hasMoreTokens()) {
                            ant[a] = Integer.parseInt(Tokenizer.nextToken());
                            a++;
                        }
                        Searching ab=new Searching();
                        int c=Integer.parseInt(editText.getText().toString());
                        Searching.linearSearch(ant,0,5,c);
                        editText2.setText( Searching.linearSearch(ant,0,5,c)+" ");
                    }

                });
                botton2.setOnClickListener(new View.OnClickListener() {


                    @Override
                    public void onClick(View v) {
                        StringTokenizer Tokenizer = new StringTokenizer(editText1.getText().toString());
                        Integer[] ant = new Integer [6];
                        int a = 0;
                        while (Tokenizer.hasMoreTokens()) {
                            ant[a] = Integer.parseInt(Tokenizer.nextToken());
                            a++;
                        }
                        Searching ab=new Searching();
                        int c=Integer.parseInt(editText.getText().toString());
                        Sorting.binarySearchTreeSort(ant);
                        editText2.setText( ab.binarySearch(ant,0,5,c)+" ");
                    }

                });
                botton3.setOnClickListener(new View.OnClickListener() {


                    @Override
                    public void onClick(View v) {
                        StringTokenizer Tokenizer = new StringTokenizer(editText1.getText().toString());
                        Integer[] ant = new Integer [6];
                        int a = 0;
                        while (Tokenizer.hasMoreTokens()) {
                            ant[a] = Integer.parseInt(Tokenizer.nextToken());
                            a++;
                        }
                        Searching ab=new Searching();
                        int c=Integer.parseInt(editText.getText().toString());
                        Searching.linearSearch(ant,0,5,c);
                        Sorting.binarySearchTreeSort(ant);
                        editText2.setText( ab.InterpolationSearch(ant,c)+" ");
                    }

                });
                botton4.setOnClickListener(new View.OnClickListener() {


                    @Override
                    public void onClick(View v) {
                        StringTokenizer Tokenizer = new StringTokenizer(editText1.getText().toString());
                        Integer[] ant = new Integer [6];
                        int a = 0;
                        while (Tokenizer.hasMoreTokens()) {
                            ant[a] = Integer.parseInt(Tokenizer.nextToken());
                            a++;
                        }
                        Searching ab=new Searching();
                        int c=Integer.parseInt(editText.getText().toString());
                        Searching.linearSearch(ant,0,5,c);
                        Sorting.binarySearchTreeSort(ant);
                        editText2.setText( Searching.FibonacciSearch(ant,0,5,c)+" ");
                    }

                }); botton5.setOnClickListener(new View.OnClickListener() {


                    @Override
                    public void onClick(View v) {
                        StringTokenizer Tokenizer = new StringTokenizer(editText1.getText().toString());
                        Integer[] ant = new Integer [6];
                        int a = 0;
                        while (Tokenizer.hasMoreTokens()) {
                            ant[a] = Integer.parseInt(Tokenizer.nextToken());
                            a++;
                        }
                        Searching ab=new Searching();
                        int c=Integer.parseInt(editText.getText().toString());
                        Searching.linearSearch(ant,0,5,c);
                        editText2.setText( ab.BinarySearchTreeSearch(ant,0,5,c)+" ");
                    }

                }); botton6.setOnClickListener(new View.OnClickListener() {


                    @Override
                    public void onClick(View v) {
                        StringTokenizer Tokenizer = new StringTokenizer(editText1.getText().toString());
                        Integer[] ant = new Integer [6];
                        int a = 0;
                        while (Tokenizer.hasMoreTokens()) {
                            ant[a] = Integer.parseInt(Tokenizer.nextToken());
                            a++;
                        }
                        Searching ab=new Searching();
                        int c=Integer.parseInt(editText.getText().toString());
                        Sorting.binarySearchTreeSort(ant);
                        editText2.setText( ab.partitionSearch(ant,0,5,c)+" ");
                    }

                }); botton7.setOnClickListener(new View.OnClickListener() {


                    @Override
                    public void onClick(View v) {
                        StringTokenizer Tokenizer = new StringTokenizer(editText1.getText().toString());
                        Integer[] ant = new Integer [6];
                        int a = 0;
                        while (Tokenizer.hasMoreTokens()) {
                            ant[a] = Integer.parseInt(Tokenizer.nextToken());
                            a++;
                        }
                        Searching ab=new Searching();
                        int c=Integer.parseInt(editText.getText().toString());
                        Searching.linearSearch(ant,0,5,c);
                        editText2.setText( ab.Hashsearching(ant,c)+" ");
                    }

                });


                Button button10 =(Button)findViewById(R.id.button10);
                button10.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(MainActivity.this,Main2Activity.class);
                        startActivity(intent);
                    }
                });


            }
        }


